import Vue from 'vue'
import VueRouter from 'vue-router'

// import Home from '../views/Home.vue'
// import Tag from '../views/Tag.vue'
// import Timeline from '../views/Timeline.vue'
// import LeaveMessage from '../views/LeaveMessage.vue'
// import About from '../views/About.vue'
// import ArticleInfo from '../views/ArticleInfo.vue'

// import discovery from '../views/01.discovery.vue'
// import playlists from '../views/02.playlists.vue'
// import songs from '../views/03.songs.vue'
// import mvs from '../views/04.mvs.vue'
// import result from '../views/05.result.vue'
// import playlist from '../views/06.playlist.vue'
// import mv from '../views/07.mv.vue'

// 路由懒加载
const Home = () => import('../views/home/Home.vue')
const Tag = () => import('../views/tag/Tag.vue')
const Timeline = () => import('../views/timeLine/Timeline.vue')
const LeaveMessage = () => import('../views/leaveMessage/LeaveMessage.vue')
const About = () => import('../views/about/About.vue')
const ArticleInfo = () => import('../views/articleInfo/ArticleInfo.vue')

const discovery = () => import('../views/01.discovery.vue')
const playlists = () => import('../views/02.playlists.vue')
const songs = () => import('../views/03.songs.vue')
const mvs = () => import('../views/04.mvs.vue')
const result = () => import('../views/05.result.vue')
const playlist = () => import('../views/06.playlist.vue')
const mv=()=>import('../views/07.mv.vue')


// 解决两次访问相同路由地址报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: {
      title:'首页'
    }
  },
  {
    path: '/tag',
    component: Tag,
    meta: {
      title:'标签'
    },
    redirect: '/tag/discovery',
    children: [
      { path: 'discovery', component: discovery },
      { path: 'playlists', component: playlists },
      { path: 'songs', component: songs },
      { path: 'mvs', component: mvs },
      { path: 'result', component: result },
      { path: 'playlist', component: playlist },
      { path: 'mv', component: mv },
    ]
  },
  {
    path: '/timeline',
    component: Timeline,
    meta: {
      title:'时间线'
    }
  },
  {
    path: '/message',
    component: LeaveMessage,
    meta: {
      title:'留言板'
    }
  },
  {
    path: '/about',
    component: About,
    meta:{
      title:'关于'
    }
  },
  {
    path: '/articleInfo/:id',
    component: ArticleInfo,
    meta: {
      title:'文章'
    }
  },
]

const router = new VueRouter({
  routes
})

// 路由导航守卫
// to表示即将跳往的路由
router.beforeEach((to, from, next) => {
  document.title=to.matched[0].meta.title
  next()
})

export default router
